﻿using Architecture.CrossCutting.Common.Dependency;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Architecture.CrossCutting.Common
{
    public class CustomContext
    {
        public static CustomContext Current = new CustomContext();

        private IExecutionContext _underlyingContext;

        private IExecutionContext UnderlyingContext
        {
            get
            {
                if (_underlyingContext != null) { return _underlyingContext; }
                else
                {
                    var context = this.DependencyResolver.GetService<IExecutionContext>();
                    if (context == null)
                    {
                        throw new Exception("The Architecture.CrossCutting.Common.CustomContext has not been correctly initialized");
                    }
                    _underlyingContext = context;
                    return _underlyingContext;
                }
            }
        }

        public UnityResolver DependencyResolver { get; set; }

        public Guid ExecutionId
        {
            get
            {
                return this.UnderlyingContext.ExecutionId;
            }
            set
            {
                this.UnderlyingContext.ExecutionId = value;
            }
        }
    }
}
